home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11090 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  54 lines

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: a typedef question
  5. Date: 21 Mar 1996 13:56:42 -0500
  6. Organization: University of Maryland Baltimore County
  7. Distribution: us
  8. Message-ID: <4is8pa$rnd@umbc9.umbc.edu>
  9. References: <4ilq55$4oo@newserv.ksu.ksu.edu> <4is8hu$rc4@umbc9.umbc.edu>
  10. NNTP-Posting-Host: umbc9.umbc.edu
  11. NNTP-Posting-User: schlein
  12.  
  13. Bin Chen <binchen@phys.ksu.edu> wrote:
  14. |> Here is the question:
  15. |>  
  16. |>         typedef struct A {
  17. |>                 ......
  18. |>                 struct B one_attr;
  19. |>                 ......
  20. |>         };
  21. |> 
  22. |>         typedef struct B {
  23. |>                 ......
  24. |>                 struct A two_attr;
  25. |>                 ......
  26. |>         };
  27. |>  
  28. |> Is this OK? How do you make it correct if it is not right?
  29.  
  30. Actually it's not right...I can't see why you are using typedef when
  31. no alias is being attributed to your struct names. Get rid of those
  32. keywords and you should be ok. Otherwise, choose an appropriate alternate
  33. identifier for your structures.
  34.  
  35. Also your structures contain each other mutually which will cause
  36. infinite recursion if such a thing could ever exist. Perhaps what you
  37. want is pointers to structures?
  38.  
  39. I'd try the following:
  40.  
  41. struct A
  42. {
  43.   struct B * one_attr;
  44. };
  45.  
  46. struct B
  47. {
  48.   struct A * two_attr;
  49. };
  50. -- 
  51. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  52.  
  53. Jonas J. Schlein  (schlein@gl.umbc.edu)
  54.